Skip to content

Update adjust-selector-specificity.ts #951

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed

Conversation

nmn
Copy link

@nmn nmn commented Apr 17, 2023

Uses a smaller :not rule to bump specificty.

Uses a smaller `:not` rule to bump specificty.
@romainmenke
Copy link
Member

Hi @nmn, thank you for your contribution.

This change would break the cascade layers fallback for older browsers.
:not() with complex selector support is a recent feature.

Was there some issue in particular you are trying solve?

}

return list;
return `:not(${list})`;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@romainmenke
Copy link
Member

@nmn Going to close this pull requests because this change would limit the usefulness of the plugin, but please open an issue if there are any problems you are trying to solve.

@nmn
Copy link
Author

nmn commented Apr 19, 2023

Looking at the MDN page, only selector “lists” seem to be a new feature. A repeated ID selector should work even in older browsers?

I will reopen once I can test support. Thanks!

@romainmenke
Copy link
Member

romainmenke commented Apr 19, 2023

A repeated ID selector doesn't produce the right specificity, so that would definitely not work :)

You can test this by running npm run build and then npm run test:browser.
That will verify the plugin against the same sort of tests as Chrome, Safari, Firefox use to verify their native feature.

These tests will fail if you change the plugin to produce :not(#\#, #\#)


Also, we tested this extremely thoroughly, if there was a way to produce smaller CSS we would change to that in a heartbeat, but the current implementation is exactly as it should be :)

@nmn
Copy link
Author

nmn commented Apr 20, 2023

@romainmenke My fix would have generated :not(#\##\#) and not :not(#\#, #\#) which has the right specificity.

However, I tested in Chrome 49 (as that is the oldest browser I need to support at work) and as stated, the double ID selector failed to work.

This is surprising to me because the new part of the specification is “selector lists” (many selectors separated by a comma). However, testing beats looking at specifications.

I guess the polyfill can’t be made any smaller!

Thanks for taking the time!

@nmn nmn deleted the patch-1 branch April 20, 2023 06:22
@romainmenke
Copy link
Member

The old version of :not() only supported a single simple selector, so only :not(.foo), not :not(.foo.bar), :not(.foo, .bar), :not(.foo > .bar), ...

It is true that the MDN labeling is confusing :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants